package tech.smartboot.redisun.cmd;

import org.smartboot.socket.transport.WriteBuffer;
import tech.smartboot.redisun.RedisSerialization;
import tech.smartboot.redisun.resp.BulkStrings;
import tech.smartboot.redisun.resp.RESP;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 三刀
 * @version v1.0 10/23/25
 */
abstract class Command implements RedisSerialization {
    private final List<BulkStrings> params = new ArrayList<>();

    protected abstract void addParams(List<BulkStrings> param);

    @Override
    public final void writeTo(WriteBuffer writeBuffer) throws IOException {
        addParams(params);
        List p = params;
        RESP.ofArray(p).writeTo(writeBuffer);
    }
}
